package com.example.testproj.utils;

import android.content.Context;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @des:
 * @author: 芮勤
 * @date: 2019/2/22 17:26
 * @see {@link }
 */
public class FileUtils {
    public static byte[] getFromAssets(Context context,String fileName){
        try {

            return readInStream(context.getResources().getAssets().open(fileName));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    //将输入流转换成字节数组
    private static byte[] readInStream(InputStream is) throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        int len = -1;
        while ((len = is.read(buf)) != -1) {
            baos.write(buf, 0, len);
        }
        return baos.toByteArray();
    }
}
